package org.kfive.nova.io;

import org.apache.log4j.Logger;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PushbackInputStream;

/*
* PushBackIO.java
* Created  by  dell
* Created on 2016/3/10 16:19
*/
public class PushBackIO {

    private static Logger LOG = Logger.getLogger(PushBackIO.class);

    public static void read() throws IOException {
        String content = "hello,hello world";
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content.getBytes());
        PushbackInputStream pushbackInputStream = new PushbackInputStream(byteArrayInputStream);
        int temp = 0;
        while ((temp=pushbackInputStream.read())!=-1){
            if(temp==','){
                pushbackInputStream.unread(temp);
                temp = pushbackInputStream.read();
                LOG.info("(回退" + (char) temp + ") ");
            }else {
                LOG.info((char) temp);
            }
        }
    }

    public static void main(String[] args) {
        try {
            PushBackIO.read();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
